package com.huifaapp.mall.activity;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.ClipboardUtils;
import com.blankj.utilcode.util.FileIOUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.FutureTarget;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.gyf.barlibrary.ImmersionBar;
import com.huifaapp.mall.APP;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.ShopkeeperAdapter;;
import com.huifaapp.mall.adapter.TribeFragmentListviewAdapter;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.api.ObserverCallback;
import com.huifaapp.mall.bean.InviteCollarNow;
import com.huifaapp.mall.bean.JDlianjie;
import com.huifaapp.mall.bean.ShareImageBean;
import com.huifaapp.mall.bean.ShareStoreBean;
import com.huifaapp.mall.bean.Tmall_StoreHEADBean;
import com.huifaapp.mall.bean.Tmall_shopkeeperGoodsBean;
import com.huifaapp.mall.bean.Tmall_shopkeeper_hostGoodsBean;
import com.huifaapp.mall.bean.TribeDetailsBean;
import com.huifaapp.mall.dialogs.LoadingDialog;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.huifaapp.mall.uitils.CircleTransform;
import com.huifaapp.mall.uitils.Contig;
import com.huifaapp.mall.uitils.MyListView;
import com.huifaapp.mall.uitils.ShareUtils;
import com.huifaapp.mall.uitils.UtilsImage;
import com.huifaapp.mall.view.CenterDialog;
import com.huifaapp.mall.view.CenterDialogTrue;
import com.huifaapp.mall.view.CenterDialogTrueIsYunDianZhu;
import com.huifaapp.mall.view.CenterDialogYouCode;
import com.huifaapp.mall.view.CustomViewpagertwo;

import com.huifaapp.mall.view.ShowBean;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.kepler.jd.Listener.LoginListener;
import com.kepler.jd.login.KeplerApiManager;
import com.kepler.jd.sdk.exception.KeplerBufferOverflowException;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.squareup.okhttp.Request;
import com.squareup.picasso.Picasso;
import com.tencent.mm.sdk.platformtools.BackwardSupportUtil;
import com.tencent.mm.sdk.platformtools.Log;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;


import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

import static com.huifaapp.mall.afinal.Constants.savePath;
import static com.huifaapp.mall.uitils.Contig.typex;

/**
 *精选店铺页面
 */

public class Tmall_shopkeeperFragment extends Fragment  implements CenterDialog.OnCenterItemClickListener ,
        CenterDialogTrue.OnCenterItemClickListener,CenterDialogTrueIsYunDianZhu.OnCenterItemClickListener,View.OnClickListener{
    CenterDialog centerDialog;
    CenterDialogYouCode centerDialogYouCode;
    CenterDialogTrue centerDialogTrue;
    CenterDialogTrueIsYunDianZhu centerDialogTrueIsYunDianZhu;
    private TextView tv_fragment_ruzhu;
    EditText et_tribe_phone;
    EditText et_tribe_weixinhao;
    EditText et_tribe_InvitateCode;
    CheckBox checkbox_tribe_Invitecode;
    private MyListView mylv_tribe_title;
    private ImageView  iv_tribe_image;
    private View mview;
    private XRecyclerView tmall_shopkeeper_recyclerView;
    private  String  HEADURL=ApiManager.BASE_NIUPAI_URL+"users/yunindex";
    private  String HOSTGOODSURL=ApiManager.BASE_NIUPAI_URL+"users/hostGoods";
    private  String REOCMGOODSURL=ApiManager.BASE_NIUPAI_URL+"users/recomGoods";
    private List<ShowBean> imgelist = new ArrayList<>();
    private CustomViewpagertwo tmall_shopkeeper_CustomViewpagertwo;
    private ShowBean show;
    private ImageView modification_store_imge;
    private TextView store_textView;
    private EditText conceal_editText;
    private View cccc;
    private Button confirm_butten;
    private LinearLayout tmallshopkeeper_detail;
    private static final int GALLERY_CODE = 2;
    private static final int CROP_CODE = 3;
    private LinearLayout tmll_detailye_balancecccc;
    private LinearLayout tmll_detailye_team_ccccc;
    private String deviceid;
    private int WRITE_EXTERNAL_STORAGE_REQUEST_CODE = 1;
    String str="";
    public static String IMEI = null;
    private TextView tmall_shopkeeper_balance;
    private ImageView avatarImageView;
    private TextView tmall_shopkeeper_team;
    private TextView activity_tmll_detail_preProfit;
    private TextView tmallshopkeeper_actualProfit;
    private TextView tmall_shopkeeper_indent;
    private Tmall_StoreHEADBean.DataBean data;
    private Uri pictureuri;
    private List<Tmall_shopkeeper_hostGoodsBean.DataBean.ListBean> goodsBeanlist;
    private int start;
    public static Map<Integer, Boolean> hmap;
    private ShopkeeperAdapter shopkeeperAdapter;
    private LinearLayout ll_kaidian;
    private LinearLayout ll_yaoqingruzhu;
    private LinearLayout ll_yaoqingvip;
    private ImageView iv_tab_fenxiang_frage;
    ArrayList<String> idlist = new ArrayList<>();
    private static final int SHARET_WXHY = 517;
    private ImageView edit_search;
    private String phone;
    private TextView tv_tmallshopkeep_code;
    private TextView tv_tmallshopkeep_fuzhi;
    private LinearLayout ll_yugu;
    private LinearLayout ll_leijishouyi;
    private ImageView iv_share_dianpu;
    private ShareStoreBean.DataBean shreData;
    private int location;
    private JDlianjie jDlianjiebean;
    private String datayouhui;
    private String datalisnajie;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (mview == null) {
            mview = inflater.inflate(R.layout.tmall_shopkeeperhead, container, false);
//            ImmersionBar.with(getActivity()).init();
            hmap = new HashMap<>();
            initView(mview);
            initHeadHttp();
            initStormHttp();
            initRecomGoodsHttp();
            ModificationName();

        }

        return mview;
    }
    private void initView(View view) {
        ll_kaidian= (LinearLayout) view.findViewById(R.id.ll_kaidian);
        tv_fragment_ruzhu= (TextView) view.findViewById(R.id.tv_fragment_ruzhu);
        mylv_tribe_title= (MyListView) view.findViewById(R.id.mylv_tribe_title);
        iv_tribe_image= (ImageView) view.findViewById(R.id.iv_tribe_image);
        tv_fragment_ruzhu.setOnClickListener(this);
        iv_tab_fenxiang_frage= (ImageView) view.findViewById(R.id.iv_tab_fenxiang_frage);

        centerDialog = new CenterDialog(getActivity(), R.layout.dialog_layout,
                new int[]{R.id.iv_cancel_dialog,R.id.et_tribe_phone, R.id.et_tribe_weixinhao,R.id.et_tribe_InvitateCode,R.id.checkbox_tribe_Invitecode,R.id.tv_tribe_true_submit});
        centerDialog.setOnCenterItemClickListener(this);

        centerDialogTrue = new CenterDialogTrue(getActivity(), R.layout.dialog_layout_true,
                new int[]{R.id.tv_true_tribe,R.id.tv_dialog_neirong});
        centerDialogTrue.setOnCenterItemClickListener(this);
        centerDialogTrueIsYunDianZhu = new CenterDialogTrueIsYunDianZhu(getActivity(), R.layout.dialog_layout_is_yundianzhu,
                new int[]{R.id.tv_true_tribe_yundianzhu});
        centerDialogTrueIsYunDianZhu.setOnCenterItemClickListener(this);
        Loadshendetails();
        if(SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN).equals("")){
            iv_tab_fenxiang_frage.setVisibility(View.GONE);
//            Intent intent=new Intent(getActivity(),LoginActivity.class);
//            startActivity(intent);
        }else {
            iv_tab_fenxiang_frage.setVisibility(View.GONE);
            ll_kaidian.setVisibility(View.VISIBLE);
            Loadkaidian();
        }
        goodsBeanlist = new ArrayList<>();
        tmall_shopkeeper_recyclerView = (XRecyclerView) mview.findViewById(R.id.tmall_shopkeeper_recyclerView);
        tmall_shopkeeper_recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2, GridLayoutManager.VERTICAL, false));
        shopkeeperAdapter = new ShopkeeperAdapter(goodsBeanlist,getActivity());
        tmall_shopkeeper_recyclerView.setAdapter(shopkeeperAdapter);
        tmall_shopkeeper_recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                start = 0;

                Loadshendetails();
                Invitelaod();
                initHeadHttp();
                initStormHttp();
                initRecomGoodsHttp();
                ModificationName();
                initStormHttp();
            }

            @Override
            public void onLoadMore() {
                start++;
                initStormHttp();
                //tmall_shopkeeper_recyclerView.loadMoreComplete();
            }
        });
        initStormHttp();

        cccc = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_tmallshopkeeper, null);
        tv_tmallshopkeep_code = (TextView) cccc.findViewById(R.id.tv_tmallshopkeep_code);
        tv_tmallshopkeep_fuzhi = (TextView) cccc.findViewById(R.id.tv_tmallshopkeep_fuzhi);
        iv_share_dianpu = (ImageView) cccc.findViewById(R.id.iv_share_dianpu);
        iv_share_dianpu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoadShareStore();
            }
        });
        tmall_shopkeeper_recyclerView.addHeaderView(cccc);
        store_textView = (TextView) cccc.findViewById(R.id.store_TextView);
        edit_search = (ImageView) cccc.findViewById(R.id.edit_search);
        edit_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(),SearActivity.class);
                startActivity(intent);
            }
        });
        Invitelaod();
        ll_yaoqingruzhu = (LinearLayout) cccc.findViewById(R.id.ll_yaoqingruzhu);
        ll_yaoqingvip = (LinearLayout) cccc.findViewById(R.id.ll_yaoqingvip);
        conceal_editText = (EditText) cccc.findViewById(R.id.conceal_EditText);
        modification_store_imge = (ImageView) cccc.findViewById(R.id.modification_store_imge);
        confirm_butten = (Button) cccc.findViewById(R.id.confirm_Butten);
        avatarImageView = (ImageView) cccc.findViewById(R.id.avatarImageView);
        tmallshopkeeper_detail = (LinearLayout) cccc.findViewById(R.id.tmallshopkeeper_detail);
        tmll_detailye_balancecccc = (LinearLayout) cccc.findViewById(R.id.tmll_detailye_balanceccccc);
        tmll_detailye_team_ccccc = (LinearLayout) cccc.findViewById(R.id.tmll_detailye_team_ccccc);
        tmall_shopkeeper_balance = (TextView) cccc.findViewById(R.id.tmall_shopkeeper_balance);
//        tmall_shopkeeper_team = (TextView) cccc.findViewById(R.id.tmall_shopkeeper_team);
        activity_tmll_detail_preProfit = (TextView) cccc.findViewById(R.id.activity_tmll_detail_preProfit);
        tmallshopkeeper_actualProfit = (TextView) cccc.findViewById(R.id.tmallshopkeeper_actualProfit);
        tmall_shopkeeper_indent = (TextView) cccc.findViewById(R.id.tmall_shopkeeper_indent);
        tmallshopkeeper_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(),TmllshopkeeperDetailActivity.class);
                intent.putExtra("userImg",data.getUserImg());
                intent.putExtra("userNickName",data.getUserNickName());
                intent.putExtra("balcance",data.getBalcance()+"");
                intent.putExtra("preProfit",data.getPreProfit()+"");
                android.util.Log.e("preProfit",data.getPreProfit()+"");
                intent.putExtra("actualProfit",data.getActualProfit()+"");
                intent.putExtra("orderNum",data.getOrderNum()+"");
                startActivity(intent);
            }
        });
        ll_yugu= (LinearLayout) cccc.findViewById(R.id.ll_yugu);
        ll_yugu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(),TmllshopkeeperDetailActivity.class);
                intent.putExtra("userImg",data.getUserImg());
                intent.putExtra("userNickName",data.getUserNickName());
                intent.putExtra("balcance",data.getBalcance()+"");
                intent.putExtra("preProfit",data.getPreProfit()+"");
                android.util.Log.e("preProfit",data.getPreProfit()+"");
                intent.putExtra("actualProfit",data.getActualProfit()+"");
                intent.putExtra("orderNum",data.getOrderNum()+"");
                startActivity(intent);
            }
        });
        ll_leijishouyi= (LinearLayout) cccc.findViewById(R.id.ll_leijishouyi);
        ll_leijishouyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(),TmllshopkeeperDetailActivity.class);
                intent.putExtra("userImg",data.getUserImg());
                intent.putExtra("userNickName",data.getUserNickName());
                intent.putExtra("balcance",data.getBalcance()+"");
                intent.putExtra("preProfit",data.getPreProfit()+"");
                android.util.Log.e("preProfit",data.getPreProfit()+"");
                intent.putExtra("actualProfit",data.getActualProfit()+"");
                intent.putExtra("orderNum",data.getOrderNum()+"");
                startActivity(intent);
            }
        });
        avatarImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                chooseFromGallery();
            }
        });
        tmll_detailye_balancecccc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent=new Intent(getActivity(),WithdrawalSubsidiaryActivity.class);
//                startActivity(intent);

                Intent intent = new Intent(getActivity(),DepositActivity.class);
                startActivity(intent);
            }
        });
        tmll_detailye_team_ccccc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent=new Intent(getActivity(),Tmall_shopkeeperFragment_team.class);
                startActivity(Intent);
            }
        });
        ll_yaoqingruzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(getActivity(),InviteCollarNowActivity.class);
                startActivity(intent);
            }
        });
        ll_yaoqingvip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(getActivity(),InvitationVIPActivity.class);
                startActivity(intent);
            }
        });
        iv_tab_fenxiang_frage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                android.util.Log.e("数据Toady", Contig.checkedIndexkeep + "-=====Contig.checkedIndex===id");
                if (Contig.checkedIndexkeep.size() == 0) {
                    Toast.makeText(getActivity(), "没有选择，请选择再分享！", Toast.LENGTH_SHORT).show();
                } else {
                    for (int i = 0; i < Contig.checkedIndexkeep.size(); i++)
                        idlist.add(goodsBeanlist.get(Contig.checkedIndexkeep.get(i)).getId());

                    android.util.Log.e("数据Toady", idlist + "-===========id");


                    StringBuffer permission = new StringBuffer();
                    for (int i = 0; i < idlist.size(); i++) {
                        if (i == 0) {
                            permission.append(idlist.get(i));
                        } else {
                            permission.append("," + idlist.get(i));
                        }
                        Contig.listididkeep.add(idlist.get(i));

                    }
//                    LoadStoreList(0, 0, Contig.listidid);

                    ApiManager
                            .getInstance()
                            .getApiServer()
                            .getShareImage(SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN), AUniqueIdentifier.getDeviceId(getActivity()), permission.toString())
                            .compose(ApiManager.<ShareImageBean>handlResult())
                            .subscribe(new ObserverCallback<ShareImageBean>(getActivity()) {
                                @Override
                                protected void onSuccessful(ShareImageBean resp) {

                                    saveImage(resp.getPoster(), resp.getFailure(), SHARET_WXHY);
                                    if (Contig.checkedIndexkeep.size() > 0) {
                                        for (int a = 0; a < Contig.checkedIndexkeep.size(); a++) {
                                            Contig.ShareListkeep.add(goodsBeanlist.get(Contig.checkedIndexkeep.get(a)).getId());
                                        }
                                    }
                                    shopkeeperAdapter = new ShopkeeperAdapter(goodsBeanlist,getActivity());
                                    tmall_shopkeeper_recyclerView.setAdapter(shopkeeperAdapter);

                                }

                                @Override
                                protected void onError(String code, String errMsg) {
                                    ToastUtils.showShortSafe(errMsg);
                                }
                            });
                    idlist.clear();
                }
            }
        });
    }

    private void LoadShareStore() {
        String url=ApiManager.SHARE_STORE+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+AUniqueIdentifier.getDeviceId(getActivity());
        android.util.Log.e("分享店铺",url);
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                ShareStoreBean shareStoreBean= gson.fromJson(response,ShareStoreBean.class);
                if(shareStoreBean.getCode().equals("10000")){
                    shreData = shareStoreBean.getData();
                    final UMWeb web = new UMWeb(shareStoreBean.getData().getLink().getUrl());
                    web.setTitle(shareStoreBean.getData().getLink().getTitle());//标题
                    web.setThumb(new UMImage(getActivity(), shareStoreBean.getData().getLink().getImgUrl()));  //缩略图
                    web.setDescription(shareStoreBean.getData().getLink().getContent());//描述
                    shareUrl( "3",null,web,null);
                }else{
                    Toast.makeText(getActivity(),shareStoreBean.getMsg(),Toast.LENGTH_SHORT);
                }

            }
        });
    }
    /**
     * 分享链接
     */

    private void shareUrl(String type, String con, UMWeb web, UMImage image) {

        android.util.Log.v("shiran","-----------shareUrl()----------");


        UMShareListener umShareListener = new UMShareListener() {
            @Override
            public void onStart(SHARE_MEDIA share_media) {
//                if (dialog!=null&&!dialog.isShowing()) {
//                    dialog.show();
//                }
            }

            @Override
            public void onResult(SHARE_MEDIA share_media) {
                if (share_media == SHARE_MEDIA.WEIXIN) {
                    ToastUtils.showShortSafe("微信分享成功");
                    Contig.shar=1;
                } else if (share_media == SHARE_MEDIA.WEIXIN_CIRCLE) {
                    ToastUtils.showShortSafe("朋友圈分享成功");
                    Contig.shar=1;
                } else {
                    ToastUtils.showShortSafe("分享成功");
                    Contig.shar=1;

                }
            }

            @Override
            public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                if (share_media == SHARE_MEDIA.WEIXIN) {
                    ToastUtils.showShortSafe("微信分享失败");

                } else if (share_media == SHARE_MEDIA.WEIXIN_CIRCLE) {
                    ToastUtils.showShortSafe("朋友圈分享失败");
                } else {
                    ToastUtils.showShortSafe("分享失败");

                }
            }

            @Override
            public void onCancel(SHARE_MEDIA share_media) {
                if (share_media == SHARE_MEDIA.WEIXIN) {
                    ToastUtils.showShortSafe("微信分享取消");

                } else if (share_media == SHARE_MEDIA.WEIXIN_CIRCLE) {
                    ToastUtils.showShortSafe("朋友圈分享取消");
                } else {
                    ToastUtils.showShortSafe("分享取消");

                }
            }
        };

        if ("3".equals(type)) {  //分享微信
            new ShareAction(getActivity())
                    .setPlatform(SHARE_MEDIA.WEIXIN).
                    setCallback(umShareListener)
                    .withMedia(web)
                    .share();

        }
    }
    private void Invitelaod(){
        android.util.Log.e("邀请","url=============="+ApiManager.BASE_NIUPAI_URL+"users/invite/yun"+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+ AUniqueIdentifier.getDeviceId(getActivity()));
        OkHttpUtils.get().url(ApiManager.BASE_NIUPAI_URL+"users/invite/yun"+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+AUniqueIdentifier.getDeviceId(getActivity()))
                .build()
                .execute(new StringCallback() {

                    @Override
                    public void onError(Request request, Exception e) {

                    }

                    @Override
                    public void onResponse(String response) {
                        Gson gson = new Gson();
                        final InviteCollarNow list = gson.fromJson(response,InviteCollarNow.class);
                        if(list.getCode().equals("10000")){
                            tv_tmallshopkeep_code.setText(list.getData().getInvitingCode());
                            tv_tmallshopkeep_fuzhi.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    ClipboardUtils.copyText(list.getData().getInvitingCode());
                                    Toast.makeText(getActivity(),"复制成功",Toast.LENGTH_SHORT).show();
                                }
                            });
                        }else if(list.getCode().equals("10001")){
                            Intent intent=new Intent(getActivity(),LoginActivity.class);
                            startActivity(intent);
                        }else if(list.getCode().equals("10002")){
                            Intent intent=new Intent(getActivity(),LoginActivity.class);
                            startActivity(intent);
                        }else{
                            Toast.makeText(getActivity(),list.getMsg(),Toast.LENGTH_SHORT).show();
                        }

                    }
                });
    }
    private void saveImage(List<String> imageUrls, final String cconten, final int type) {

        android.util.Log.v("shiran", "------------saveImage------------");

        final LoadingDialog dialog = new LoadingDialog(getActivity());
        dialog.setContent("正在生成图片请稍后");


        Observable.just(imageUrls)
                .map(new Function<List<String>, List<String>>() {

                    @Override
                    public List<String> apply(List<String> list) throws Exception {

                        List<String> paths = new ArrayList<String>();
                        for (String s : list) {
                            FutureTarget<File> future = Glide.with(APP.getInstance())
                                    .load(s)
                                    .downloadOnly(500, 500);
                            File cacheFile = future.get();
                            String uuid = UUID.randomUUID().toString();
                            FileIOUtils.writeFileFromIS(savePath + uuid + ".jpg", new FileInputStream(cacheFile));
                            String pat = savePath + uuid + ".jpg";
                            paths.add(pat);

                        }


                        return paths;
                    }
                }).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<String>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        if (dialog != null && !dialog.isShowing()) {
                            dialog.show();
                        }
                    }

                    @Override
                    public void onNext(List<String> value) {
                        LogUtils.e(value);
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                            dialog.cancel();
                        }

                        switch (type) {
                            case SHARET_WXHY:


                                ShareUtils.sharePicToFriendNoSDK(getActivity(), value);
//                                        ClipboardUtils.copyText(cconten);
//                                        ToastUtils.showShortSafe("内容已复制!");

                                break;
//                            case SHARET_WXPYQ:
//                                ShareUtils.share9PicsToWXCircle(getActivity(), "", value);
//                                break;
                            default:

                                break;
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                            dialog.cancel();
                        }
                    }

                    @Override
                    public void onComplete() {
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                            dialog.cancel();
                        }
                    }
                });

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_fragment_ruzhu:
                Loadkaidians();
//

                break;
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        Loadkaidian();
    }

    @Override
    public void OnCenterItemClick(CenterDialog dialog, View view) {
        et_tribe_phone= (EditText) dialog.findViewById(R.id.et_tribe_phone);
        et_tribe_phone.setText(phone);
        et_tribe_weixinhao= (EditText) dialog.findViewById(R.id.et_tribe_weixinhao);
        et_tribe_InvitateCode= (EditText) dialog.findViewById(R.id.et_tribe_InvitateCode);
        checkbox_tribe_Invitecode= (CheckBox) dialog.findViewById(R.id.checkbox_tribe_Invitecode);
        if(checkbox_tribe_Invitecode.isChecked()) {
            et_tribe_InvitateCode.setVisibility(View.VISIBLE);

        }else{
            et_tribe_InvitateCode.setVisibility(View.GONE);

        }
        switch (view.getId()) {
            case R.id.tv_tribe_true_submit:
                Loadshenqing();
                break;
            case R.id.iv_cancel_dialog:
                centerDialog.dismiss();
                break;
        }


    }



    @Override
    public void OnCenterItemClick(CenterDialogTrue dialog, View view) {
        switch (view.getId()){
            case R.id.tv_true_tribe:
                centerDialogTrue.dismiss();
                break;
        }
    }
    @Override
    public void OnCenterItemClick(CenterDialogTrueIsYunDianZhu dialog, View view) {
        switch (view.getId()){
            case R.id.tv_true_tribe_yundianzhu:
                centerDialogTrueIsYunDianZhu.dismiss();
                break;
        }
    }
    private void Loadshendetails(){
        String url = ApiManager.USERS_OPENSTORE_INDEX;

        android.util.Log.e("数据", "进入--" + url);
        HttpUtils http = new HttpUtils();
        //http://www.jhjvip.cn:8081/market/mobile/jd/index?
        http.send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
//                  testTextView.setText(current + "/" + total);
                com.umeng.socialize.utils.Log.e("数据", "数据-------" + current + "/" + total);
            }

            //
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
//                    textView.setText(responseInfo.result);
                try {
                    com.umeng.socialize.utils.Log.e("数据123", "数据d-------" + responseInfo.result);
                    Gson gson = new Gson();
                    TribeDetailsBean list = gson.fromJson(responseInfo.result, TribeDetailsBean.class);
                    if(list.getCode().equals("10000")) {
                        UtilsImage.uploadimageview(iv_tribe_image,list.getData().getBanner(),"",getActivity());
                        TribeFragmentListviewAdapter adapter=new TribeFragmentListviewAdapter(getActivity(),list.getData().getList());
                        mylv_tribe_title.setAdapter(adapter);
                    }else{
                        Toast.makeText(getActivity(),list.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                }catch (JsonSyntaxException e){
                    Toast.makeText(getActivity(),"未知错误",Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onFailure(HttpException error, String msg) {
            }
        });
    }
    private void Loadshenqing(){
        String url = ApiManager.USERS_OPENSTORE_RUZHU+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)
                +"&appId="+ AUniqueIdentifier.getDeviceId(getActivity())+"&phone="+et_tribe_phone.getText().toString().trim()
                +"&weixinAccount="+et_tribe_weixinhao.getText().toString().trim()
                +"&inviteCode="+et_tribe_InvitateCode.getText().toString().trim();

        android.util.Log.e("数据", "进入--" + url);
        HttpUtils http = new HttpUtils();
        //http://www.jhjvip.cn:8081/market/mobile/jd/index?
        http.send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
//                  testTextView.setText(current + "/" + total);
                com.umeng.socialize.utils.Log.e("数据", "数据-------" + current + "/" + total);
            }

            //
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
//                    textView.setText(responseInfo.result);
                try {
                    com.umeng.socialize.utils.Log.e("数据123", "数据d-------" + responseInfo.result);
                    JSONObject obj=new JSONObject(responseInfo.result);
                    if(obj.getString("code").equals("10000")) {
                        Loadkaidian();
                        Toast.makeText(getActivity(),obj.getString("msg"),Toast.LENGTH_SHORT).show();
                        centerDialog.dismiss();
                        centerDialogTrue.show();

                    }else{
                        Toast.makeText(getActivity(),obj.getString("msg"),Toast.LENGTH_SHORT).show();
                    }
                }catch (JsonSyntaxException e){
                    Toast.makeText(getActivity(),"未知错误",Toast.LENGTH_LONG).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onStart() {
            }

            @Override
            public void onFailure(HttpException error, String msg) {
            }
        });
    }
    private void Loadkaidians(){
        String url = ApiManager.USERS_OPENSTO+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+ AUniqueIdentifier.getDeviceId(getActivity());

        android.util.Log.e("数据", "进入--" + url);
        HttpUtils http = new HttpUtils();
        //http://www.jhjvip.cn:8081/market/mobile/jd/index?
        http.send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
//                  testTextView.setText(current + "/" + total);
                com.umeng.socialize.utils.Log.e("数据", "数据-------" + current + "/" + total);
            }

            //
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
//                    textView.setText(responseInfo.result);
                try {
                    com.umeng.socialize.utils.Log.e("数据123", "数据d-------" + responseInfo.result);
                    JSONObject obj=new JSONObject(responseInfo.result);
                    if(obj.getString("code").equals("10000")) {
                        centerDialog.show();
                    }else if(obj.getString("code").equals("10001")) {
                        iv_tab_fenxiang_frage.setVisibility(View.GONE);
                        Intent intent=new Intent(getActivity(),LoginActivity.class);
                        startActivity(intent);
                    }else if(obj.getString("code").equals("10002")) {
                        iv_tab_fenxiang_frage.setVisibility(View.GONE);
                        Intent intent=new Intent(getActivity(),LoginActivity.class);
                        startActivity(intent);
                    }else if(obj.getString("code").equals("10077")){
//                        centerDialogTrueIsYunDianZhu.show();
                        phone = obj.getString("data");
                        ll_kaidian.setVisibility(View.GONE);
                        iv_tab_fenxiang_frage.setVisibility(View.VISIBLE);
                        tv_fragment_ruzhu.setText("已是云店主");
                        Loadshendetails();
                        Invitelaod();
                        initHeadHttp();
                        initStormHttp();
                        initRecomGoodsHttp();
                        ModificationName();
                        initStormHttp();
                    }else if(obj.getString("code").equals("10080")){
                        iv_tab_fenxiang_frage.setVisibility(View.GONE);
                        tv_fragment_ruzhu.setText("待审核");
                        tv_fragment_ruzhu.setBackgroundResource(R.color.login_text);
                        tv_fragment_ruzhu.setTextColor(Color.rgb(152,152,152));
                    }else{
                        iv_tab_fenxiang_frage.setVisibility(View.GONE);
                        Toast.makeText(getActivity(),obj.getString("msg"),Toast.LENGTH_SHORT).show();
                    }
                }catch (JsonSyntaxException e){
                    Toast.makeText(getActivity(),"未知错误",Toast.LENGTH_LONG).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onStart() {
            }

            @Override
            public void onFailure(HttpException error, String msg) {
            }
        });
    }
    private void Loadkaidian(){
        String url = ApiManager.USERS_OPENSTO+"?token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+ AUniqueIdentifier.getDeviceId(getActivity());

        android.util.Log.e("数据", "进入--" + url);
        HttpUtils http = new HttpUtils();
        //http://www.jhjvip.cn:8081/market/mobile/jd/index?
        http.send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
//                  testTextView.setText(current + "/" + total);
                com.umeng.socialize.utils.Log.e("数据", "数据-------" + current + "/" + total);
            }

            //
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
//                    textView.setText(responseInfo.result);
                try {
                    com.umeng.socialize.utils.Log.e("数据123", "数据d-------" + responseInfo.result);
                    JSONObject obj=new JSONObject(responseInfo.result);
                    if(obj.getString("code").equals("10000")) {
//                        centerDialog.show();
                        phone = obj.getString("data");

                    }else if(obj.getString("code").equals("10077")){
//                        centerDialogTrueIsYunDianZhu.show();
                        ll_kaidian.setVisibility(View.GONE);
                        iv_tab_fenxiang_frage.setVisibility(View.VISIBLE);
                        tv_fragment_ruzhu.setText("已是云店主");
                        Loadshendetails();
                        Invitelaod();
                        initHeadHttp();
                        initStormHttp();
                        initRecomGoodsHttp();
                        ModificationName();
                        initStormHttp();
                    }else{
//                        Toast.makeText(getActivity(),obj.getString("msg"),Toast.LENGTH_SHORT).show();
                    }
                }catch (JsonSyntaxException e){
                    Toast.makeText(getActivity(),"未知错误",Toast.LENGTH_LONG).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onStart() {
            }

            @Override
            public void onFailure(HttpException error, String msg) {
            }
        });
    }

    private void requestEmit(String response) {
        Gson gson = new Gson();
        Tmall_shopkeeper_hostGoodsBean tmall_shopkeeper_hostGoodsBean = gson.fromJson(response, Tmall_shopkeeper_hostGoodsBean.class);

        if (tmall_shopkeeper_hostGoodsBean.getCode().equals("10000")) {
            if (tmall_shopkeeper_hostGoodsBean != null && tmall_shopkeeper_hostGoodsBean.getData() != null && tmall_shopkeeper_hostGoodsBean.getData().getList() != null) {
                if (start == 0) {
                    goodsBeanlist.clear();
                }
                goodsBeanlist.addAll(tmall_shopkeeper_hostGoodsBean.getData().getList());
                shopkeeperAdapter.notifyDataSetChanged();
            }
            tmall_shopkeeperAdapter();
        }
    }

    private void initStormHttp() {
        android.util.Log.e("toen", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
        android.util.Log.e("appid", AUniqueIdentifier.getDeviceId(getActivity()));
        OkHttpUtils.post().addParams("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)).addParams("appId", AUniqueIdentifier.getDeviceId(getActivity()))
                .addParams("start", start + "")
                .addParams("length",10 + "")
                .url(HOSTGOODSURL).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
            }
            @Override
            public void onResponse(String response) {
                try {
                    android.util.Log.e("UUUUUUUUUUUUU", response);
                    tmall_shopkeeper_recyclerView.refreshComplete();
                    requestEmit(response);
                }catch (Exception e){
                    e.printStackTrace();
                }

            }
        });

    }


    private void initHeadHttp() {
        OkHttpUtils.get().addParams("token",SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)).addParams("appId",AUniqueIdentifier.getDeviceId(getActivity())).url(HEADURL)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                android.util.Log.e("OOOOOOOOOOO",response);
                Gson gson=new Gson();
                Tmall_StoreHEADBean tmall_storeHEADBean = gson.fromJson(response, Tmall_StoreHEADBean.class);
                data = tmall_storeHEADBean.getData();

                if(tmall_storeHEADBean.getCode().equals("10000")) {
                    try {
                        Picasso.with(getActivity()).load(data.getUserImg()).transform(new CircleTransform()).into(avatarImageView);
                        store_textView.setText(data.getUserNickName());
                        tmall_shopkeeper_balance.setText(data.getBalcance() + "");
                       // tmall_shopkeeper_team.setText(data.getMyteamNum() + "");
                        activity_tmll_detail_preProfit.setText(data.getPreProfit() + "");
                        tmallshopkeeper_actualProfit.setText(data.getActualProfit() + "");
                        tmall_shopkeeper_indent.setText(data.getOrderNum() + "");
                    } catch (Exception e) {
                        //Picasso.with(getActivity()).load(data.getUserImg()).transform(new CircleTransform()).into(avatarImageView);
                        store_textView.setText("");
                        tmall_shopkeeper_balance.setText(0+ "");
                        // tmall_shopkeeper_team.setText(data.getMyteamNum() + "");
                        activity_tmll_detail_preProfit.setText(0+ "");
                        tmallshopkeeper_actualProfit.setText(0+ "");
                        tmall_shopkeeper_indent.setText(0+ "");
                    }
                }else  if (tmall_storeHEADBean.getCode().equals("10001")){
//                    Intent intent=new Intent(getActivity(),LoginActivity.class);
//                    startActivity(intent);
                }else
                if (tmall_storeHEADBean.getCode().equals("10055")){
                    //判断是否是云店主
                    ll_kaidian.setVisibility(View.VISIBLE);

                }



            }
        });
    }

    //修改店铺名称方法
    private void ModificationName() {
        modification_store_imge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // Toast.makeText(getActivity(),"修改店铺名",Toast.LENGTH_LONG).show();
                modification_store_imge.setVisibility(View.GONE);
                store_textView.setVisibility(View.GONE);
                CharSequence text = store_textView.getText();
                conceal_editText.setText(text);
                conceal_editText.setVisibility(View.VISIBLE);
                confirm_butten.setVisibility(View.VISIBLE);

            }
        });
        confirm_butten.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Editable text = conceal_editText.getText();
                store_textView.setText(text);
                conceal_editText.setVisibility(View.GONE);
                confirm_butten.setVisibility(View.GONE);
                modification_store_imge.setVisibility(View.VISIBLE);
                store_textView.setVisibility(View.VISIBLE);
            }
        });
    }


    private void tmall_shopkeeperAdapter() {
        shopkeeperAdapter.setmMyItemclickListener(new ShopkeeperAdapter.MyShopkeeperItemclickListener() {
            @Override
            public void Shopkeeperitemclick(View view, int position) {
//             Intent intent=new Intent(getActivity(),ShoppingCartActivity.class);
//                intent.putExtra("shopid",goodsBeanlist.get(position).getId());
//                intent.putExtra("typex", Contig.typex);
//                startActivity(intent);


                if (goodsBeanlist.get(position).getSpuPlatform().equals("yh")) {
                    Intent intent = new Intent(getActivity(), Red_PacketActivity.class);
                    intent.putExtra("shopid", goodsBeanlist.get(position).getId());
                    intent.putExtra("typex", Contig.typex);
                    startActivity(intent);
                } else {
                    android.util.Log.e("getCouponMoney====",goodsBeanlist.get(position).getCouponMoney()+"    ");
                    location = position;
                    if (goodsBeanlist.get(position).getSpuPlatform().equals("jd")) {
                        if (goodsBeanlist.get(position).getCouponMoney()==0) {
                            initJDputong();
                            if(KeplerApiManager.getWebViewService().isKeplerLogined()){
                                try {
                                    if(jDlianjiebean.getData().equals("")||jDlianjiebean.getData().equals("null")||jDlianjiebean.getData().equals(null)){

                                    }else {
                                        KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                    }
                                } catch (KeplerBufferOverflowException e) {
                                    e.printStackTrace();
                                }

                            }else {
                                final LoginListener mLoginListener = new LoginListener() {
                                    @Override
                                    public void authSuccess(Object token) {
                                        // TODO Auto-generated method stub
                                        Toast.makeText(getActivity(), token + "", Toast.LENGTH_SHORT).show();
                                        //                showToken();

                                        if (KeplerApiManager.getWebViewService().isKeplerLogined()) {
                                            try {
                                                KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                            } catch (KeplerBufferOverflowException e) {
                                                e.printStackTrace();
                                            }
                                        }

                                    }

                                    @Override
                                    public void authFailed(int errorCode) {
                                        // TODO Auto-generated method stub
                                        switch (errorCode) {
                                            case KeplerApiManager.KeplerApiManagerLoginErr_Init:// 初始化失败 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_InitIng:// 初始化没有完成 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_openH5authPageURLSettingNull://跳转url // 为null break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_getTokenErr:// 获取失败(OAuth授权之后，获取cookie过程出错) break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_User_Cancel:// 用户取消 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_AuthErr_ActivityOpen://打开授权页面失败 break;
                                            default:
                                                break;
                                        }
//                Toast.makeText(AllOrderActivity.this, errorCode + ":authFailed", Toast.LENGTH_SHORT).show();
                                        android.util.Log.e("jdSHOUQUAN", errorCode + ":authFailed");
                                    }
                                };
                                KeplerApiManager.getWebViewService().login(getActivity(), mLoginListener);
                            }
//                            Intent intent = new Intent(getActivity(), HtmlActivity.class);
//                            intent.putExtra("data", datalisnajie);
//                            intent.putExtra("shopid", goodsBeanlist.get(location).getId());
//                            startActivity(intent);
                        }
                        if (0 != goodsBeanlist.get(position).getCouponMoney()) {
                            if (goodsBeanlist.get(position).getCouponMoney()==0.0) {
                                Map<String, String> map = new HashMap<>();
                                map.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                                map.put("spuId", goodsBeanlist.get(location).getId());
                                map.put("appid", AUniqueIdentifier.getDeviceId(getActivity()));
                                android.util.Log.e("优惠二和一链接接口", ApiManager.BASE_NIUPAI_URL+ goodsBeanlist.get(location).getSpuPlatform()+"/getConUrl" + "?token=" + SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN) + "&spuId=" + goodsBeanlist.get(location).getId() + "&appid=" + AUniqueIdentifier.getDeviceId(getActivity()));
                                OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+ goodsBeanlist.get(location).getSpuPlatform()+"/getConUrl").build().execute(new StringCallback() {
                                    @Override
                                    public void onError(Request request, Exception e) {

                                    }

                                    @Override
                                    public void onResponse(String response) {
                                        android.util.Log.e("优惠二和一数据", response);
                                        Gson gson = new Gson();
                                        jDlianjiebean = gson.fromJson(response, JDlianjie.class);
                                        datayouhui = jDlianjiebean.getData();
                                        if (jDlianjiebean.getCode().equals("10000")) {
                                            Intent intent = new Intent(getActivity(), JDred_packetActivity.class);
                                            intent.putExtra("shopid", goodsBeanlist.get(location).getId());
                                            startActivity(intent);
                                        }
                                    }
                                });

                            } else {
                                Map<String, String> map = new HashMap<>();
                                map.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                                map.put("spuId", goodsBeanlist.get(location).getId());
                                map.put("appid", AUniqueIdentifier.getDeviceId(getActivity()));

                                OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+ goodsBeanlist.get(location).getSpuPlatform()+"/getConUrl").build().execute(new StringCallback() {
                                    @Override
                                    public void onError(Request request, Exception e) {

                                    }

                                    @Override
                                    public void onResponse(String response) {
                                        android.util.Log.e("优惠二和一数据aaa", response);
                                        Gson gson = new Gson();
                                        jDlianjiebean = gson.fromJson(response, JDlianjie.class);
                                        datayouhui = jDlianjiebean.getData();
                                        if (jDlianjiebean.getCode().equals("10000")) {
                                            android.util.Log.e("data==","data==========="+jDlianjiebean.getData());
                                            if (jDlianjiebean.getData() == null||jDlianjiebean.getData() == ""||jDlianjiebean.getData() == "null"||jDlianjiebean.getData().equals("")) {


                                            }else {
                                                if(KeplerApiManager.getWebViewService().isKeplerLogined()){
                                                    try {
                                                        KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                                    } catch (KeplerBufferOverflowException e) {
                                                        e.printStackTrace();
                                                    }

                                                }else {
                                                    final LoginListener mLoginListener = new LoginListener() {
                                                        @Override
                                                        public void authSuccess(Object token) {
                                                            // TODO Auto-generated method stub
                                                            Toast.makeText(getActivity(), token + "", Toast.LENGTH_SHORT).show();
                                                            //                showToken();

                                                            if (KeplerApiManager.getWebViewService().isKeplerLogined()) {
                                                                try {
                                                                    KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                                                } catch (KeplerBufferOverflowException e) {
                                                                    e.printStackTrace();
                                                                }
                                                            }

                                                        }

                                                        @Override
                                                        public void authFailed(int errorCode) {
                                                            // TODO Auto-generated method stub
                                                            switch (errorCode) {
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_Init:// 初始化失败 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_InitIng:// 初始化没有完成 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_openH5authPageURLSettingNull://跳转url // 为null break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_getTokenErr:// 获取失败(OAuth授权之后，获取cookie过程出错) break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_User_Cancel:// 用户取消 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_AuthErr_ActivityOpen://打开授权页面失败 break;
                                                                default:
                                                                    break;
                                                            }
//                Toast.makeText(AllOrderActivity.this, errorCode + ":authFailed", Toast.LENGTH_SHORT).show();
                                                            android.util.Log.e("jdSHOUQUAN", errorCode + ":authFailed");
                                                        }
                                                    };
                                                    KeplerApiManager.getWebViewService().login(getActivity(), mLoginListener);
                                                }
//                                                Intent intent = new Intent(getActivity(), HtmlActivity.class);
//                                                intent.putExtra("shopid", goodsBeanlist.get(location).getId());
//                                                intent.putExtra("data", datayouhui);
//                                                startActivity(intent);
                                            }
                                        }
                                    }
                                });
                            }
                        }
                    }
                }
            }
        });

    }
    //普通二和一链接
    private void initJDputong(){
        try {
            Map<String, String> map = new HashMap<String, String>();
            map.put("spuId", goodsBeanlist.get(location).getId());
            map.put("appid", AUniqueIdentifier.getDeviceId(getActivity()));
            map.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
            android.util.Log.e("京东二合一转链", ApiManager.BASE_NIUPAI_URL+goodsBeanlist.get(location).getSpuPlatform()+"/getUrl" + "?spuId=" + goodsBeanlist.get(location).getId() + "&appId=" + AUniqueIdentifier.getDeviceId(getActivity()) + "&token=" + SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
            OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+goodsBeanlist.get(location).getSpuPlatform()+"/getUrl").build().execute(new StringCallback() {
                @Override
                public void onError(Request request, Exception e) {

                }
                @Override
                public void onResponse(String response) {
                    android.util.Log.e("fgdgfe", response);
                    Gson gson = new Gson();
                    JDlianjie jDlianjie = gson.fromJson(response, JDlianjie.class);
                    datalisnajie = jDlianjie.getData();
                    android.util.Log.e("kfjsdkghdfk", datalisnajie);

                }
            });
        }catch (Exception e){

        }
    }

    public Object getData() {
        return data;
    }
    public  void  initRecomGoodsHttp(){

        OkHttpUtils.post().addParams("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)).
                addParams("appId", AUniqueIdentifier.getDeviceId(getActivity()))
                .url(ApiManager.BASE_NIUPAI_URL+typex+"/recomGoods")
                .build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                android.util.Log.e("VVVVVVVVVVVV",response);
                Gson gson=new Gson();
                Tmall_shopkeeperGoodsBean tmall_shopkeeperGoodsBean = gson.fromJson(response, Tmall_shopkeeperGoodsBean.class);
                if(tmall_shopkeeperGoodsBean.getCode().equals("10000")) {
                    List<Tmall_shopkeeperGoodsBean.DataBean.ListBean> GoodsBeanlist = new ArrayList<Tmall_shopkeeperGoodsBean.DataBean.ListBean>();
                    GoodsBeanlist.addAll(tmall_shopkeeperGoodsBean.getData().getList());
                    tmall_shopkeeper_CustomViewpagertwo.setsData(GoodsBeanlist);
                }else {
                    Toast.makeText(getActivity(),tmall_shopkeeperGoodsBean.getMsg(),Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    /**
     * 从相册选择图片
     */
    private void chooseFromGallery() {
        //构建一个内容选择的Intent
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        //设置选择类型为图片类型
        intent.setType("image/*");
        //打开图片选择
        startActivityForResult(intent, GALLERY_CODE);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode){
            case GALLERY_CODE:
                if (data == null){
                    return;
                }else{
                    //用户从图库选择图片后会返回所选图片的Uri
                    Uri uri;
                    //获取到用户所选图片的Uri
                    uri = data.getData();
                    //返回的Uri为content类型的Uri,不能进行复制等操作,需要转换为文件Uri
                    uri = convertUri(uri);
                    startImageZoom(uri);
                }
                break;
            case CROP_CODE:
                if (data == null){
                    return;
                }else{
                    Bundle extras = data.getExtras();
                    if (extras != null){
                        //获取到裁剪后的图像
                        Bitmap bm = extras.getParcelable("data");
                        avatarImageView.setImageBitmap(bm);

                    }

                }
                break;
            default:
                break;
        }

        if (data == null){
            return;
        }else {
            //用户从图库选择图片后会返回所选图片的Uri

            //获取到用户所选图片的Uri
            pictureuri = data.getData();
            //返回的Uri为content类型的Uri,不能进行复制等操作,需要转换为文件Uri
            if (pictureuri ==null){
                return;
            }
            pictureuri = convertUri(pictureuri);
            startImageZoom(pictureuri);
        }

    }




    private Uri convertUri(Uri uri){
        InputStream is;
        try {
            //Uri ----> InputStream
            is = getContext().getContentResolver().openInputStream(uri);
            //InputStream ----> Bitmap
            Bitmap bm = BackwardSupportUtil.BitmapFactory.decodeStream(is);
            //关闭流
            is.close();
            return saveBitmap(bm, "temp");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }



    private Uri saveBitmap(Bitmap bm, String dirPath) {
        //新建文件夹用于存放裁剪后的图片
        File tmpDir = new File(Environment.getExternalStorageDirectory() + "/" + dirPath);
        if (!tmpDir.exists()){
            tmpDir.mkdir();
        }

        //新建文件存储裁剪后的图片
        File img = new File(tmpDir.getAbsolutePath() + "/avator.png");
        try {
            //打开文件输出流
            FileOutputStream fos = new FileOutputStream(img);
            //将bitmap压缩后写入输出流(参数依次为图片格式、图片质量和输出流)
            bm.compress(Bitmap.CompressFormat.JPEG, 40, fos);
            //刷新输出流
            fos.flush();
            //关闭输出流
            fos.close();
            //返回File类型的Uri
            return Uri.fromFile(img);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

    }

    private void startImageZoom(Uri uri){
        //构建隐式Intent来启动裁剪程序
        Intent intent = new Intent("com.android.camera.action.CROP");
        //设置数据uri和类型为图片类型
        intent.setDataAndType(uri, "image/*");
        //显示View为可裁剪的
        intent.putExtra("crop", true);
        //裁剪的宽高的比例为1:1
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        //输出图片的宽高均为150
        intent.putExtra("outputX", 150);
        intent.putExtra("outputY", 150);
        //裁剪之后的数据是通过Intent返回
        intent.putExtra("return-data", true);
        intent.clone();
        startActivityForResult(intent, CROP_CODE);
    }



}

